package com.example.myapplication;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class Main2Activity extends AppCompatActivity implements View.OnClickListener{

    private TextView tv;
    private int textSize = 0;
    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        Button btn = findViewById(R.id.button);
        btn.setOnClickListener( this );
        tv = findViewById(R.id.textView);
        tv.setTextSize(50);
    }

    @Override
    public void onClick(View view) {
        //TODO 显示一个AlertDialog

        AlertDialog.Builder builder =
                new AlertDialog.Builder(this )
                .setTitle("设置字体大小")

                 .setSingleChoiceItems(
                         new String[]{"小号", "大号"},
                         textSize,
                         new DialogInterface.OnClickListener() {
                             @Override
                             public void onClick(DialogInterface dialogInterface, int i) {
                                 textSize = i;
                                 Toast.makeText(getBaseContext(),   i+"", Toast.LENGTH_SHORT).show();
                             }
                         }
                 )

                .setIcon(R.drawable.ic_warning)
                .setPositiveButton(
                    "确定",
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                            if(textSize == 0) {
                                tv.setTextSize(50);
                            } else if(textSize == 1) {
                                tv.setTextSize(100);
                            }
                        }
                    }
                )
                .setNegativeButton(
                        "结束",
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                                Toast.makeText(getBaseContext(),"结束", Toast.LENGTH_SHORT).show();
                            }
                        }
                )
                .setNeutralButton(
                        "取消",
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                                Toast.makeText(getBaseContext(),"取消", Toast.LENGTH_SHORT).show();
                            }
                        }
                );

        builder.create().show();



    }
}
